package ru.amse.baltijsky.javascheme.importer.test;

import ru.amse.baltijsky.javascheme.importer.IImporter;
import static ru.amse.baltijsky.javascheme.importer.test.TestImporterTools.createNodeDeeperLevel;
import static ru.amse.baltijsky.javascheme.importer.test.TestImporterTools.createNodeSameLevel;
import static ru.amse.baltijsky.javascheme.tree.NodeType.*;
import ru.amse.baltijsky.javascheme.tree.SchemaNode;
import ru.amse.baltijsky.javascheme.tree.SchemaTree;
import ru.amse.baltijsky.javascheme.tree.TranslationUnitNode;

import java.io.IOException;
import java.io.Reader;

/**
 * A dumb importer for importing code like {@code MyTest1.java}.
 */
public class SampleImporterTest1 implements IImporter {
    /**
     * Dumb implementation of the loadTree method. Always returns a sample tree for the following code:
     * public void doSomeJob() {
     * }
     * <p/>
     * public void f(int b) {
     * int a = 10;
     * doSomeJob();
     *
     * @param in         ignored
     * @param className
     * @param methodName
     * @return the root of the artificially constructed tree
     */
    public SchemaTree loadTree(Reader in, String className, String methodName) {
        // create a dumb class and a function to which the code will belong to
        // the root of the resulting tree
        SchemaNode root = new TranslationUnitNode();
        // the node that is being constructed: cur
        SchemaNode cur = createNodeDeeperLevel(CLASS, root, new String[]{"Dumb"});
        cur = createNodeDeeperLevel(METHOD, cur, new String[]{"void f()"});

        // create the code
        cur = createNodeDeeperLevel(ACTION, cur, new String[]{"int a = 10;"});
        createNodeSameLevel(ACTION, cur, new String[]{"doSomeJob();"});

        return new SchemaTree(root);
    }

    public SchemaTree[] loadTrees(Reader in) throws IOException {
        return new SchemaTree[0];
    }

    public String[] getClasses(Reader in) throws IOException {
        return new String[0];
    }

    public String[] getMethods(Reader in, String className) throws IOException {
        return new String[0];
    }
}
